/**
 *
 */
package tec.data.persistence.oracle;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import oracle.jdbc.pool.OracleDataSource;

public class OCIConnectionHelper {
	public Connection getConnection(BasicConnectionParameter p) throws SQLException {
		OracleDataSource ods = new OracleDataSource();
		ods.setServerName(p.getHost());
		ods.setPortNumber(p.getPort());
		ods.setDatabaseName(p.getSid());
		ods.setUser(p.getUserName());
		ods.setPassword(p.getPassword());
		ods.setDriverType("oci");
		
		return(ods.getConnection());	
	}
	
	public Connection getConnection(TNSConnectionParameter p) throws SQLException {
		OracleDataSource ods = new OracleDataSource();
		ods.setTNSEntryName(p.getTNSName());
		ods.setUser(p.getUserName());
		ods.setPassword(p.getPassword());
		ods.setDriverType("oci");
		
		return(ods.getConnection());	
	}
	
	public Connection getJDBCConnection(TNSConnectionParameter p) throws SQLException {
		/*
		 * Oracle connection string:
		 * - jdbc:oracle:oci:@tnsname
		 * - jdbc:oracle:oci:user/password@tnsname
		 */
		String url = "jdbc:oracle:oci:@" + p.getTNSName();
		String user = p.getUserName();
		String password = p.getPassword();
		Connection con = DriverManager.getConnection(url, user, password);
			
		return(con);
	}	
}
